import React from 'react'
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'
import MainLayout from './components/Layout/MainLayout'
import Login from './pages/Login/index'
import Dashboard from './pages/Dashboard/index'
import WideTableManagement from './pages/WideTable/WideTableManagement'
import ExcelImport from './pages/WideTable/ExcelImport'
import DataComponentProcessing from './pages/DataComponent/DataComponentProcessing'
import ChartComponentProcessing from './pages/ChartComponent/ChartComponentProcessing'
import ComponentLibraryManagement from './pages/ComponentLibrary/ComponentLibraryManagement'
import ThemeScenarioManagement from './pages/ThemeScenario/ThemeScenarioManagement'
import ApprovalManagement from './pages/Approval/ApprovalManagement'
import { useAuth } from './hooks/useAuth'

const App: React.FC = () => {
  const { isAuthenticated } = useAuth()

  return (
    <Router>
      <Routes>
        <Route path="/login" element={<Login />} />
        <Route
          path="/*"
          element={
            isAuthenticated ? (
              <MainLayout>
                <Routes>
                  <Route path="/" element={<Navigate to="/dashboard" replace />} />
                  <Route path="/dashboard" element={<Dashboard />} />
                  <Route path="/wide-table" element={<WideTableManagement />} />
                  <Route path="/wide-table/import" element={<ExcelImport />} />
                  <Route path="/data-component" element={<DataComponentProcessing />} />
                  <Route path="/chart-component" element={<ChartComponentProcessing />} />
                  <Route path="/component-library" element={<ComponentLibraryManagement />} />
                  <Route path="/theme-scenario" element={<ThemeScenarioManagement />} />
                  <Route path="/approval" element={<ApprovalManagement />} />
                </Routes>
              </MainLayout>
            ) : (
              <Navigate to="/login" replace />
            )
          }
        />
      </Routes>
    </Router>
  )
}

export default App